#include "game_over_text.h"

extern int G_W, G_H;

GAME_OVER_TEXT::GAME_OVER_TEXT(CASH *cash)
{
    this->setZValue(1);

    tl_anims = new QTimeLine(1000, this);
    tl_anims->setEasingCurve(QEasingCurve::Type(7));

    item_game = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value("Res/text/game_over/game.png"), this);
    item_over = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value("Res/text/game_over/over.png"), this);

    anim_init();
}

GAME_OVER_TEXT::~GAME_OVER_TEXT(){}

QPainterPath GAME_OVER_TEXT::shape() const
{
    return QPainterPath();
}


void GAME_OVER_TEXT::anim_init()
{
    //animations for item game
    QGraphicsItemAnimation *anim_game = new QGraphicsItemAnimation(this);
    anim_game->setItem(item_game);
    anim_game->setTimeLine(tl_anims);

    anim_game->setPosAt(1, QPointF(362,328));
    anim_game->setPosAt(0, anim_game->posAt(1) - QPointF(G_W, 0));

    item_game->setPos(-G_W,0);

    //animations for item_over
    QGraphicsItemAnimation *anim_over = new QGraphicsItemAnimation(this);
    anim_over->setItem(item_over);
    anim_over->setTimeLine(tl_anims);

    anim_over->setPosAt(1, QPointF(713, 328));
    anim_over->setPosAt(0, anim_over->posAt(1) + QPointF(G_W, 0));

    item_over->setPos(G_W, 0);
}

void GAME_OVER_TEXT::anim_show()
{
    tl_anims->stop();
    tl_anims->setDirection(QTimeLine::Forward);
    tl_anims->start();
}

void GAME_OVER_TEXT::anim_hide()
{
    tl_anims->stop();
    tl_anims->setDirection(QTimeLine::Backward);
    tl_anims->start();
}
